# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=binaryen
pkgver=40
pkgrel=1
pkgdesc="Compiler infrastructure and toolchain library for WebAssembly, in C++"
options="!check" # Tests require python2
url="https://github.com/WebAssembly/binaryen"
arch="all !s390x !mips !mips64"
license="Apache-2.0"
makedepends="cmake"
checkdepends="nodejs" # python2"
subpackages="$pkgname-dev"
source="binaryen-$pkgver.tar.gz::https://github.com/WebAssembly/binaryen/archive/version_$pkgver.tar.gz
	link-dynamically.patch
	ignore-type-limits-error.patch
	fix-gcc8-wcatch-value.patch
	gcc-march-aarch64.patch"
builddir="$srcdir/$pkgname-version_$pkgver"

case "$CARCH" in
	x86) options="!check";;  # XXX: two tests fail
esac

build() {
	cmake \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DBUILD_SHARED_LIBS=ON
	make
}

check() {
	# waterfall requires additional dependency
	# gcc-tests fail, dunno why
	python2 check.py --no-test-waterfall --no-run-gcc-tests
}

package() {
	make install DESTDIR="$pkgdir"
	rm "$pkgdir"/usr/share/binaryen/binaryen.js
}

sha512sums="89aa73c1686fb6d54c91990acbc7cd6c1bc7e6da57731bf009fe507c955c98c91582b5b9924c3c3f6a2d36d55ae73f1be79911cdce93dfd74954bca46861c8ad  binaryen-40.tar.gz
9729655be0d952385de959bf7dd84a075b192fe4b221bb5c23e562a83a2bf9202a07536ad393157b23e0447f28bdd16283f64a63588ca42597bb59e9551219c8  link-dynamically.patch
3b95a197cd8805dfa714cf9f31adc1437b6d29bd4082f752c16d98c40cd024b110c02a412285c78251cb5d0b3080c0f9e4d45d8dd0166c71b9462b1610191ab8  ignore-type-limits-error.patch
f937a9f9f7f2cab97aa15ade3a800b8924755b27ae4e9e8951ee97dc79d54c95db28d3c71b32c2ed0b5711d6e1884c33cc307564abe759f6ea3c23db60d433a1  fix-gcc8-wcatch-value.patch
43db7456ce3b9a6239b24caa9fc9cb1a59975e742fa74ff6bfcdadbbb453afee62842aaa973596d78294704c7d76cb73eb7703f1d66e40b1bb164e86e5da5914  gcc-march-aarch64.patch"
